home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr49 / vesa18.zip / VESA_ALL.C < prev    next >
C/C++ Source or Header  |  1995-01-28  |  9KB  |  272 lines

  1. /* VESA package for emx/gcc --- Copyright (c) 1993 by Johannes Martin */
  2. #include <string.h>
  3. #include <sys/hw.h>
  4.  
  5. #define INCL_VIO
  6. #define INCL_DOSPROCESS
  7. #define INCL_DOSFILEMGR
  8. #define INCL_DOSDEVICES
  9. #define INCL_DOSDEVIOCTL
  10.  
  11. #include <os2emx.h>
  12. #include <os2thunk.h>
  13.  
  14. #include "vgaports.h"
  15. #include "vesa.h"
  16. #include "vesadll.h"
  17. #include "common.h"
  18.  
  19. VESABOOL OS2VesaSetWindowDummy(VESACHAR Window, VESAWORD Address);
  20. VESABOOL OS2VesaGetWindowDummy(VESACHAR Window, PVESAWORD Address);
  21. VESABOOL OS2VesaSetWindowLinear(VESACHAR Window, VESAWORD Address);
  22. VESABOOL OS2VesaGetWindowLinear(VESACHAR Window, PVESAWORD Address);
  23. VESABOOL OS2VesaSetWindowPlanar(VESACHAR Window, VESAWORD Address);
  24. VESABOOL OS2VesaGetWindowPlanar(VESACHAR Window, PVESAWORD Address);
  25.  
  26. static VESAWORD _Modes[] = { 0x003, 0x012, 0x013, 0x101, 0x102, 0x103,
  27.                              0x104, 0x105, 0x106, 0x107, 0x110, 0x111,
  28.                              0x112, 0x113, 0x114, 0x115, 0x116, 0x117,
  29.                              0xFFFF };
  30.  
  31. static struct _ModeInfo _ModeInfos[] =
  32.     { { 0x1, { 0x0f, 0x7, 0x0, 64, 64, 0x0, 0x0,
  33.                OS2VesaSetWindowDummy, OS2VesaGetWindowDummy, 160,
  34.                640, 400, 8, 16, 1, 4, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  35.       { 0x3, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  36.                OS2VesaSetWindowDummy, OS2VesaGetWindowDummy, 80,
  37.                640, 480, 8, 16, 4, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  38.       { 0x3, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  39.                OS2VesaSetWindowDummy, OS2VesaGetWindowDummy, 320,
  40.                320, 200, 8,  8, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  41.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  42.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 640,
  43.                640, 480, 8, 16, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  44.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  45.                OS2VesaSetWindowDummy, OS2VesaGetWindowDummy, 100,
  46.                800, 600, 8, 16, 4, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  47.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  48.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 800,
  49.                800, 600, 8, 16, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  50.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  51.                OS2VesaSetWindowPlanar, OS2VesaGetWindowPlanar, 128,
  52.                1024, 768, 8, 16, 4, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  53.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  54.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 1024,
  55.                1024, 768, 8, 16, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  56.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  57.                OS2VesaSetWindowPlanar, OS2VesaGetWindowPlanar, 160,
  58.                1280, 1024, 8, 16, 4, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  59.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  60.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 1280,
  61.                1280, 1024, 8, 16, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  62.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  63.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 1280,
  64.                640, 480, 8, 16, 1, 15, 1, 6, 0, 1, 5, 10, 5, 5, 5, 0, 1, 15 } },
  65.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  66.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 1280,
  67.                640, 480, 8, 16, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 } },
  68.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  69.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 1920,
  70.                640, 480, 8, 16, 1, 24, 1, 6, 0, 1, 8, 16, 8, 8, 8, 0, 0, 0 } },
  71.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  72.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 1600,
  73.                800, 600, 8, 16, 1, 15, 1, 6, 0, 1, 5, 10, 5, 5, 5, 0, 1, 15 } },
  74.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  75.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 1600,
  76.                800, 600, 8, 16, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 } },
  77.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  78.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 2400,
  79.                800, 600, 8, 16, 1, 24, 1, 6, 0, 1, 8, 16, 8, 8, 8, 0, 0, 0 } },
  80.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  81.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 2048,
  82.                1024, 768, 8, 16, 1, 15, 1, 6, 0, 1, 5, 10, 5, 5, 5, 0, 1, 15 } },
  83.       { 0xb, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  84.                OS2VesaSetWindowLinear, OS2VesaGetWindowLinear, 2048,
  85.                1024, 768, 8, 16, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 } }
  86.     };
  87.  
  88. VESAWORD *Modes             = _Modes;
  89. struct _ModeInfo *ModeInfos = _ModeInfos;
  90.  
  91. HFILE ScreenHandle = 0;
  92.  
  93. VESABOOL Initialize(void)
  94. {
  95.   ULONG action;
  96.  
  97.   return(DosOpen("SCREEN$", &ScreenHandle, &action, 0, 0,
  98.                  OPEN_ACTION_OPEN_IF_EXISTS, OPEN_FLAGS_NOINHERIT |
  99.                  OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE, NULL) == 0);
  100.   return(TRUE);
  101. }
  102.  
  103. VOID ClearUp(void)
  104. {
  105.   if (ScreenHandle != 0)
  106.     DosClose(ScreenHandle);
  107. }
  108.  
  109. VOID *GetPhysBuf(void)
  110. {
  111.   VIOMODEINFO ModeInfo;
  112.   VIOPHYSBUF  PhysBuf;
  113.  
  114.   ModeInfo.cb  = sizeof(ModeInfo);
  115.   VioGetMode(&ModeInfo, 0);
  116.   PhysBuf.pBuf = (PBYTE) ModeInfo.buf_addr;
  117.   PhysBuf.cb   = 0x10000;
  118.   if (VioGetPhysBuf(&PhysBuf, 0) != 0)
  119.     return(NULL);
  120.   else
  121.     return(MAKEP(PhysBuf.asel[0], 0));
  122. }
  123.  
  124. VESABOOL SetMode(VESAWORD mode)
  125. {
  126.   VIOMODEINFO ModeInfo;
  127.  
  128.   ModeInfo.cb     = 12;
  129.   ModeInfo.fbType = ModeInfos[mode].fbtype;
  130.   ModeInfo.color  = ModeInfos[mode].Vesa.NumberOfBitsPerPixel;
  131.   ModeInfo.col    = ModeInfos[mode].Vesa.Width  / ModeInfos[mode].Vesa.CharacterWidth;
  132.   ModeInfo.row    = ModeInfos[mode].Vesa.Height / ModeInfos[mode].Vesa.CharacterHeight;
  133.   ModeInfo.hres   = ModeInfos[mode].Vesa.Width;
  134.   ModeInfo.vres   = ModeInfos[mode].Vesa.Height;
  135.   return(VioSetMode(&ModeInfo, 0) == 0);
  136. }
  137.  
  138. void SetSpecial(VESAWORD mode)
  139. {
  140. }
  141.  
  142. VESABOOL OS2VesaSetWindowDummy(VESACHAR Window, VESAWORD Address)
  143. {
  144.   return(TRUE);
  145. }
  146.  
  147. VESABOOL OS2VesaGetWindowDummy(VESACHAR Window, PVESAWORD Address)
  148. {
  149.   *Address = 0;
  150.   return(TRUE);
  151. }
  152.  
  153. VESABOOL OS2VesaSetWindowLinear(VESACHAR Window, VESAWORD Address)
  154. {
  155.   struct
  156.     {
  157.       ULONG  length;
  158.       USHORT bank;
  159.       USHORT modetype;
  160.       USHORT bankmode;
  161.     } parameter;
  162.   ULONG datalen, parmlen;
  163.  
  164.   datalen = 0;
  165.   parmlen = sizeof(parameter);
  166.   parameter.length   = sizeof(parameter);
  167.   parameter.bank     = Address;
  168.   parameter.modetype = 2;
  169.   parameter.bankmode = 0;
  170.   if (DosDevIOCtl(ScreenHandle, 0x80, 1,
  171.                   ¶meter, parmlen, &parmlen, NULL, 0, &datalen))
  172.     DosBeep(440, 500);
  173.   datalen = 0;
  174.   parmlen = sizeof(parameter);
  175.   parameter.length   = sizeof(parameter);
  176.   parameter.bank     = Address;
  177.   parameter.modetype = 2;
  178.   parameter.bankmode = 1;
  179.   if (DosDevIOCtl(ScreenHandle, 0x80, 1,
  180.                   ¶meter, parmlen, &parmlen, NULL, 0, &datalen))
  181.     DosBeep(880, 500);
  182.   return(TRUE);
  183. }
  184.  
  185. VESABOOL OS2VesaGetWindowLinear(VESACHAR Window, PVESAWORD Address)
  186. {
  187.   struct
  188.     {
  189.       ULONG  length;
  190.       USHORT bank;
  191.       USHORT modetype;
  192.       USHORT bankmode;
  193.     } parameter;
  194.   ULONG datalen, parmlen;
  195.  
  196.   datalen = 0;
  197.   parmlen = sizeof(parameter);
  198.   parameter.length   = sizeof(parameter);
  199.   parameter.modetype = 2;
  200.   parameter.bankmode = 0;
  201.   if (DosDevIOCtl(ScreenHandle, 0x80, 0,
  202.                   ¶meter, parmlen, &parmlen, NULL, 0, &datalen))
  203.     DosBeep(220, 500);
  204.   *Address = parameter.bank;
  205.   return(TRUE);
  206. }
  207.  
  208. VESABOOL OS2VesaSetWindowPlanar(VESACHAR Window, VESAWORD Address)
  209. {
  210.   struct
  211.     {
  212.       ULONG  length;
  213.       USHORT bank;
  214.       USHORT modetype;
  215.       USHORT bankmode;
  216.     } parameter;
  217.   ULONG datalen, parmlen;
  218.  
  219.   datalen = 0;
  220.   parmlen = sizeof(parameter);
  221.   parameter.length   = sizeof(parameter);
  222.   parameter.bank     = Address;
  223.   parameter.modetype = 1;
  224.   parameter.bankmode = 0;
  225.   if (DosDevIOCtl(ScreenHandle, 0x80, 1,
  226.                   ¶meter, parmlen, &parmlen, NULL, 0, &datalen))
  227.     DosBeep(440, 500);
  228.   datalen = 0;
  229.   parmlen = sizeof(parameter);
  230.   parameter.length   = sizeof(parameter);
  231.   parameter.bank     = Address;
  232.   parameter.modetype = 1;
  233.   parameter.bankmode = 1;
  234.   if (DosDevIOCtl(ScreenHandle, 0x80, 1,
  235.                   ¶meter, parmlen, &parmlen, NULL, 0, &datalen))
  236.     DosBeep(880, 500);
  237.   return(TRUE);
  238. }
  239.  
  240. VESABOOL OS2VesaGetWindowPlanar(VESACHAR Window, PVESAWORD Address)
  241. {
  242.   struct
  243.     {
  244.       ULONG  length;
  245.       USHORT bank;
  246.       USHORT modetype;
  247.       USHORT bankmode;
  248.     } parameter;
  249.   ULONG datalen, parmlen;
  250.  
  251.   datalen = 0;
  252.   parmlen = sizeof(parameter);
  253.   parameter.length   = sizeof(parameter);
  254.   parameter.modetype = 1;
  255.   parameter.bankmode = 0;
  256.   if (DosDevIOCtl(ScreenHandle, 0x80, 0,
  257.                   ¶meter, parmlen, &parmlen, NULL, 0, &datalen))
  258.     DosBeep(220, 500);
  259.   *Address = parameter.bank;
  260.   return(TRUE);
  261. }
  262.  
  263. VESABOOL OS2VesaSetWindow(VESACHAR Window, VESAWORD Address)
  264. {
  265.   return(_ModeInfos[activeindex].Vesa.SetWindowFunc(Window, Address));
  266. }
  267.  
  268. VESABOOL OS2VesaGetWindow(VESACHAR Window, PVESAWORD Address)
  269. {
  270.   return(_ModeInfos[activeindex].Vesa.GetWindowFunc(Window, Address));
  271. }
  272.